#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main()
{
    long long T;
    unordered_map<char, int> sgl;
    sgl['3'] = 3, sgl['4'] = 4, sgl['5'] = 5, sgl['6'] = 6, sgl['7'] = 7, sgl['8'] = 8, sgl['9'] = 9, sgl['X'] = 10, sgl['J'] = 11, sgl['Q'] = 12, sgl['K'] = 13,
        sgl['A'] = 14, sgl['2'] = 15, sgl['M'] = 16, sgl['F'] = 17;
    unordered_set<string> com;
    com.insert("33"), com.insert("44"), com.insert("55"), com.insert("66"), com.insert("77"), com.insert("88"), com.insert("99"), com.insert("XX"),
        com.insert("JJ"), com.insert("QQ"), com.insert("KK"), com.insert("AA"), com.insert("22"), com.insert("MM"), com.insert("FF"), com.insert("MF"), com.insert("FM");
    cin >> T;
    for (long long i = 0; i < T; i++)
    {
        string s1, s2;
        cin >> s1 >> s2;
        if (com.count(s1))
        {
            cout << "ShallowDream" << endl;
            continue;
        }
        if (s2[0] == 'M' && s2[1] == 'F' || s2[1] == 'M' && s2[0] == 'F')
        {
            cout << "Joker" << endl;
            continue;
        }
        int a1 = max(sgl[s1[0]], sgl[s1[1]]);
        int a2 = max(sgl[s2[0]], sgl[s2[1]]);
        if (a1 >= a2)
        {
            cout << "ShallowDream" << endl;
            continue;
        }
        cout << "Joker" << endl;
    }
    return 0;
}

